package hos.table.simple;

import android.text.TextUtils;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.appcompat.widget.AppCompatTextView;

import com.evrencoskun.tableview.ITableView;

import hos.table.BaseTableAdapter;
import hos.table.R;
import hos.table.holder.BaseTitleTableHolder;

/**
 * <p>Title: SimpleTitleTableHolder </p>
 * <p>Description:  </p>
 * <p>Company: www.mapuni.com </p>
 *
 * @author : 蔡俊峰
 * @version : 1.0
 * @date : 2023-01-12 14:31
 */
public class SimpleTitleTableHolder extends BaseTitleTableHolder {

    public SimpleTitleTableHolder() {
        super(R.layout.simple_table);
    }

    @Override
    public View onBindView(@NonNull BaseTableAdapter adapter, @NonNull View itemView, String title) {
        AppCompatTextView value = itemView.findViewById(R.id.value);
        View dividerRight = itemView.findViewById(R.id.dividerRight);
        View dividerBottom = itemView.findViewById(R.id.dividerBottom);
        if (!TextUtils.isEmpty(title)) {
            value.setText(title);
        }
        ITableView tableView = adapter.getTableView();
        int separatorColor = tableView.getSeparatorColor();
        dividerRight.setBackgroundColor(separatorColor);
        dividerBottom.setBackgroundColor(separatorColor);
        if (tableView.isShowVerticalSeparators()) {
            dividerBottom.setVisibility(View.VISIBLE);
        } else {
            dividerBottom.setVisibility(View.GONE);
        }
        if (tableView.isShowHorizontalSeparators()) {
            dividerRight.setVisibility(View.VISIBLE);
        } else {
            dividerRight.setVisibility(View.GONE);
        }
        return itemView;
    }
}
